package com.ews.onlineexchange.controller.activitii;

import java.util.Arrays;
import java.util.List;

import javax.enterprise.inject.Model;

import com.ews.onlineexchange.model.User;
import org.activiti.engine.task.TaskQuery;

@Model
public class BestChooseEvaluationTaskList extends BpmList {

	@Override
	TaskQuery createTaskQuery() {
		TaskQuery taskQuery = taskService.createTaskQuery();

		User loginedUser = userService.getLoginedUser();
		String roleStr = loginedUser.getRoles();
		String[] roleArray = roleStr == null ? new String[]{} : roleStr.split("、");
		List<String> roles = Arrays.asList(roleArray);
		taskQuery.taskCandidateGroupIn( roles );
		
		taskQuery.includeProcessVariables();
		User user = userService.getLoginedUser();
		if(user != null){
			String userRegion = user.getRegion();
			if("370501".equals(user.getRegion()))taskQuery.processVariableValueLessThanOrEqual("supplierRegion",userRegion);
			else taskQuery.processVariableValueEquals("supplierRegion",userRegion);
		}
		taskQuery.orderByTaskCreateTime().desc();
//		taskQuery.orderByTaskCreateTime().desc();
		return taskQuery;
	}

	public BestChooseEvaluationTaskList() {
		setProcessKey( "bestChooseAudit" );
	}
	
}
